//
//  ZHFRadioListViewController.m
//  GoTraveling
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "ZHFRadioListViewController.h"

#import "ZHFListHeadView.h"

#import "ZHFRadioDetailListCell.h"

#import "GSYResources.h"

#import "ZHFRadioDetailList.h"

#import "ZHFRadioInfo.h"

@interface ZHFRadioListViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic,strong) UITableView *radioListTableView;
@property (nonatomic,strong) NSMutableArray *radioDetailListArray;
@property (nonatomic,strong) ZHFListHeadView *listHeadV;
@property (nonatomic,strong) NSMutableArray *radioArray;


@end

@implementation ZHFRadioListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = self.titleStr;
    
    self.radioListTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.radioListTableView.delegate = self;
    self.radioListTableView.dataSource = self;
    [self.view addSubview:self.radioListTableView];
    
    [self.radioListTableView registerClass:[ZHFRadioDetailListCell class] forCellReuseIdentifier:@"cell"];

    _listHeadV = [[ZHFListHeadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.frame.size.height / 2 - 40 * ADAPT_HEIGHT)];
    _radioListTableView.tableHeaderView = _listHeadV;
    
    _radioDetailListArray = [NSMutableArray array];
    _radioArray = [NSMutableArray array];
    
    _radioListTableView.rowHeight = 80 * ADAPT_HEIGHT;
    
    [self getAFNetWorkingData];
}

- (void)getAFNetWorkingData
{
    NSString *urlStr = @"http://api2.pianke.me/ting/radio_detail";
    NSString *para = [NSString stringWithFormat:@"auth=&client=1&deviceid=0F79DA7D-8DF2-416D-B3C3-7BD488A50BDD&radioid=%@&version=3.0.6", self.radioId];
    
    [GSYResources postUrl:urlStr body:para result:HXJSON requestStyle:HXRequestString headerFile:nil success:^(id result) {
        
        NSMutableDictionary *bigDic = [result objectForKey:@"data"];
        self.radioArray = [bigDic objectForKey:@"list"];
        NSMutableArray *array = [bigDic objectForKey:@"list"];
        for (NSMutableDictionary *dic in array) {
            ZHFRadioDetailList *radioDL = [[ZHFRadioDetailList alloc] init];
            [radioDL setValuesForKeysWithDictionary:dic];
            [self.radioDetailListArray addObject:radioDL];
            
        }
        
        NSMutableDictionary *infoDic = [bigDic objectForKey:@"radioInfo"];
        ZHFRadioInfo *radioInfo = [[ZHFRadioInfo alloc] init];
        [radioInfo setValuesForKeysWithDictionary:infoDic];
        self.listHeadV.radioInfo = radioInfo;
        
        [_radioListTableView reloadData];
        
    } failure:^(NSError *error) {
        
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.radioDetailListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    ZHFRadioDetailListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.radioDL = [_radioDetailListArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
